package com.wf.smartcomm.server.client.action;

import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ModelDriven;
import com.wf.smartcomm.server.bean.Bill;
import com.wf.smartcomm.server.bean.House;
import com.wf.smartcomm.server.bean.User;
import com.wf.smartcomm.server.response.ResponseCode;
import com.wf.smartcomm.server.service.BillService;

@Controller
@Scope("prototype")
public class BillAction extends BaseAction implements ModelDriven<Bill>{
	
	private Bill bill = new Bill();
	
	@Resource
	private BillService billService;
	
	
	public void listByHouse()throws Exception{
		String houseId = request.getParameter("houseId");
		billService.listByExample(new House(houseId), null, page);
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("code", ResponseCode.OK);
		map.put("data", page.getDataList());
		printJsonData(gson.toJson(map));
	}
	
	public void listByUser()throws Exception{
		String userId = request.getParameter("userId");
		billService.listByExample(null, new User(userId), page);
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("code", ResponseCode.OK);
		map.put("data", page.getDataList());
		printJsonData(gson.toJson(map));
	}

	@Override
	public Bill getModel() {
		return bill;
	}

}
